package com.shanzhu.parking.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shanzhu.parking.entity.Violation;
import com.shanzhu.parking.mapper.ViolationMapper;
import com.shanzhu.parking.service.ViolationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;

/**
 * <p>
 * 车辆违规记录表 服务实现类
 * </p>
 *
 * @author 只茂瑞
 * @since 2025-04-13
 */
@Slf4j
@Service
public class ViolationServiceImpl extends ServiceImpl<ViolationMapper, Violation> implements ViolationService {

    /**
     * 根据ID删除违规记录
     * @param id 违规记录ID
     * @return 删除结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteViolationById(Integer id) {
        if (id == null) {
            log.error("删除违规记录失败: ID为空");
            return false;
        }
        try {
            log.info("开始删除违规记录，ID: {}", id);
            int result = baseMapper.deleteById(id);
            log.info("删除违规记录结果: {}", result > 0);
            return result > 0;
        } catch (Exception e) {
            log.error("删除违规记录异常，ID: {}", id, e);
            return false;
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean removeById(Serializable id) {
        return deleteViolationById((Integer) id);
    }
}
